package cn.mesmile.shiro.module.role.mapper;

import cn.mesmile.shiro.module.role.dto.RoleVo;
import cn.mesmile.shiro.module.role.entity.Role;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author zb
 * @date 2021/02/04 15:13
 */
public interface RoleMapper extends BaseMapper<Role> {

    /**
     * 通过角色
     * @param userId
     * @return
     */
    @Select("SELECT * FROM role AS r LEFT JOIN user_role AS ur ON r.id = ur.role_id WHERE ur.user_id = #{userId}")
    @Results(
            value = {
                    @Result(property = "permissionList",column = "id",
                            many = @Many(select = "cn.mesmile.shiro.module.permission.mapper.PermissionMapper.selectPermissionListByRoleId",
                                    fetchType = FetchType.DEFAULT)
                    )
            }
    )
    List<RoleVo> findRoleByRoleId(@Param("userId")Long userId);

}
